package com.gpy.hospital.cms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gpy.hospital.cms.dao.LiuYanMapper;
import com.gpy.hospital.cms.pojo.LiuYan;
import com.gpy.hospital.cms.service.ILiuYanService;
import com.gpy.hospital.common.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author
 * @Date 2020/3/1 21:02
 * @Desc
 **/
@Service
public class LiuYanServiceImpl implements ILiuYanService {

    @Autowired
    private LiuYanMapper liuYanMapper;


    @Override
    public ServerResponse add(LiuYan liuYan) {
        liuYan.setStatus("1");
        int result = liuYanMapper.insert(liuYan);
        if (result > 0) {
            return ServerResponse.createBySuccessMessage("成功！");
        }
        return ServerResponse.createByErrorMessage("失败！");
    }

    @Override
    public PageInfo<LiuYan> get(Integer pageNum, Integer pageSize, String name) {
        PageHelper.startPage(pageNum, pageSize);
        List<LiuYan> liuYans = liuYanMapper.selectAllByEmail(name);
        return new PageInfo<>(liuYans);
    }

    @Override
    public LiuYan getById(Integer liuYanId) {
        return liuYanMapper.selectByPrimaryKey(liuYanId);
    }
}
